package com.duo.controller.admin;

import com.duo.dto.SetmealDTO;
import com.duo.dto.SetmealPageQueryDTO;
import com.duo.dto.SetmealUpdateDTO;
import com.duo.result.BaseResult;
import com.duo.service.SetmealService;
import com.duo.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: Xrx
 * @Description:
 * @CreateTime: 2023/7/7 17:39
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping("/save")
    public Object save(@RequestBody @Valid SetmealDTO setmealDTO) {
        setmealService.saveWithDish(setmealDTO);
        return BaseResult.success("新增套餐成功");
    }

    /**
     * 删除套餐
     * @param setmealId
     * @return
     */
    @DeleteMapping("/delete")
    public Object delete(@RequestBody Long setmealId) {
        setmealService.delete(setmealId);
        return BaseResult.success("删除套餐成功");
    }

    /**
     * 批量删除套餐
     * @return
     */
    @DeleteMapping("/deleteBatch")
    public Object delete(@RequestBody List<Long> setmealIds) {
        setmealService.deleteBatch(setmealIds);
        return BaseResult.success("批量删除套餐成功");
    }

    /**
     * 修改套餐
     * @param setmealDTO
     * @return
     */
    @PutMapping("/update")
    public Object update(@RequestBody SetmealUpdateDTO setmealDTO) {
        setmealService.update(setmealDTO);
        return BaseResult.success();
    }

    /**
     * 分页查询套餐
     * @return
     */
    @PostMapping("/page")
    public List<SetmealVO> list(@RequestBody SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("查询所有套餐");
        return setmealService.pageList(setmealPageQueryDTO);
    }


}
